<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ActivityAction
 *
 * @author guochen
 */

namespace Admin\Controller;

use Think\Controller;

class GameController extends CommonController {

    public function index() {
        if (!empty($_REQUEST['keys'])) {
            $map['title'] = array(
                'like',
                '%' . $_REQUEST['keys'] . '%'
            );
        }
        $map['status'] = 1;
        $gc = M('Game');

        $count = $gc->where($map)->count(); // 查询满足要求的总记录数

        $Page = new \ Think \ Page($count, C('PAGE_SIZE')); // 实例化分页类 传入总记录数
        $nowPage = !empty($_REQUEST['p']) ? $_REQUEST['p'] : 1;
        foreach ($map as $key => $val) {
            $Page->parameter .= "$key=" . urlencode($val) . "&";
        }
        $show = $Page->show(); // 分页显示输出
        $data = $gc->where($map)->order('id desc')->page($nowPage . ',' . $Page->listRows)->select();
        $this->assign('list', $data);
        $this->assign('page', $show);
        $this->display();
    }

    function loadlist() {
        if (!empty($_REQUEST['keys'])) {
            $map['title'] = array(
                'like',
                '%' . $_REQUEST['keys'] . '%'
            );
        }
        $map['status'] = 1;
        $data = M('Game')->where($map)->select();
        $count = M('Game')->where($map)->count();
        if ($data) {
            $str = '"success": true, "totalRows": ' . $count . ', "curPage": 1, "data"';
            foreach ($data as $k => $v) {
            }
            $a = $this->Export($data, $str);
        } else {

            $str = '"success": false, "totalRows": ' . $count . ', "curPage": 1, "data"';
            $a = $this->Export($data, $str);
        }
        echo $a;
    }

    public function  userList(){
        $search="";
        if (!empty($_REQUEST['members'])) {
            $search.=" and is_member=".($_REQUEST['members']-1);
        }
        $id=$_GET['id'];
        $arr['id']=$id;
        $arr['members']=$_REQUEST['members'];
        $count = M("GameScore")->where("gameid='".$id."' ".$search)->count(); // 查询满足要求的总记录数
        $Page = new \ Think \ Page($count, 10,$arr); // 实例化分页类 传入总记录数

        //$Page->parameter .= "members=" . $_REQUEST['members'] . "&";

        $nowPage = !empty($_REQUEST['p']) ? $_REQUEST['p'] : 1;
        $show = $Page->show(); // 分页显示输出
        $data = M("GameScore")->where("gameid='".$id."' ".$search)->order("score desc")->page($nowPage . ',' . $Page->listRows)->select();
        $this->assign('list', $data);
        $this->assign('page', $show);
        $this->assign('id', $id);
        $this->display();
    }


    //通过审核
    public function agree() {
        $map['id'] = $_GET['id'];
        $map['activity_id'] = $_GET['activityId'];
        $gc = M('User');
        $state = $gc->where($map)->save(array('state' => 2));
        if (!empty($state)) {
            $this->success('审核通过！', 'userList?id=' . $_GET['activityId']);
        } else {
            $this->error('审核失败！');
        }
    }



}

?>
